🧹 Remove unwrap() on required arguments in calendar helper#548
🧹 Remove unwrap() on required arguments in calendar helper#548
Conversation
Replaced `.unwrap()` calls for `calendar`, `summary`, `start`, and `end` arguments with proper error handling using `.ok_or_else()`. This prevents potential panics if the `clap` configuration were to change and instead returns a structured `GwsError::Validation` error. Added a changeset file for `@googleworkspace/cli` as a patch-level update. Co-authored-by: jpoehnelt <3392975+jpoehnelt@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
🦋 Changeset detectedLatest commit: bbaaecd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of the calendar helper by implementing proper error handling for critical, required arguments. It replaces potentially panic-inducing Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to improve error handling by removing .unwrap() calls. However, the arguments being handled (calendar, summary, start, end) are already guaranteed to be present by the clap configuration, either through required(true) or default_value(...). This means the original .unwrap() calls were safe and would never panic. The new error handling code is therefore unreachable and should be removed to avoid confusion and keep the code concise.
| let calendar_id = matches | ||
| .get_one::<String>("calendar") | ||
| .ok_or_else(|| GwsError::Validation("Missing required argument: calendar".to_string()))?; | ||
| let summary = matches | ||
| .get_one::<String>("summary") | ||
| .ok_or_else(|| GwsError::Validation("Missing required argument: summary".to_string()))?; | ||
| let start = matches | ||
| .get_one::<String>("start") | ||
| .ok_or_else(|| GwsError::Validation("Missing required argument: start".to_string()))?; | ||
| let end = matches | ||
| .get_one::<String>("end") | ||
| .ok_or_else(|| GwsError::Validation("Missing required argument: end".to_string()))?; |
There was a problem hiding this comment.
While replacing .unwrap() is generally good practice, in this specific case, the unwrap() calls were safe and would not panic. The clap argument parser is configured to ensure these values are always present:
summary,start, andendare marked asrequired(true).calendarhas adefault_value("primary").
Because of this, matches.get_one() will always return Some(...) for these arguments, and clap would have already exited with an error if a required argument was missing. The added .ok_or_else(...) introduces error handling logic that is unreachable, which can be misleading for future readers. It's better to rely on the unwrap() here, which acts as a correct assertion that the value is present.
| let calendar_id = matches | |
| .get_one::<String>("calendar") | |
| .ok_or_else(|| GwsError::Validation("Missing required argument: calendar".to_string()))?; | |
| let summary = matches | |
| .get_one::<String>("summary") | |
| .ok_or_else(|| GwsError::Validation("Missing required argument: summary".to_string()))?; | |
| let start = matches | |
| .get_one::<String>("start") | |
| .ok_or_else(|| GwsError::Validation("Missing required argument: start".to_string()))?; | |
| let end = matches | |
| .get_one::<String>("end") | |
| .ok_or_else(|| GwsError::Validation("Missing required argument: end".to_string()))?; | |
| let calendar_id = matches.get_one::<String>("calendar").unwrap(); | |
| let summary = matches.get_one::<String>("summary").unwrap(); | |
| let start = matches.get_one::<String>("start").unwrap(); | |
| let end = matches.get_one::<String>("end").unwrap(); |
References
- Avoid introducing changes that are outside the primary goal of a pull request to prevent scope creep. In this case, replacing safe
unwrap()calls with unreachable error handling adds complexity without addressing a real issue, thus deviating from a truly beneficial improvement.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #548 +/- ##
==========================================
+ Coverage 68.10% 69.07% +0.97%
==========================================
Files 40 42 +2
Lines 17954 19269 +1315
==========================================
+ Hits 12227 13310 +1083
- Misses 5727 5959 +232 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I replaced several
.unwrap()calls insrc/helpers/calendar.rswith proper error handling to improve code health and prevent potential panics. The affected arguments arecalendar,summary,start, andend, which are now handled using.ok_or_else(|| GwsError::Validation(...))?. I also added a changeset file to document the improvement.PR created automatically by Jules for task 11601507632249061943 started by @jpoehnelt